<?php
	$event = $this->event;
	$user = $this->user;
?>
<!--Start: event List-->
            <div class="boxed" style="margin-top: 10px;">
                <div class="boxTop">
                    <div class="boxTopLeft">
                        <div class="boxTopRight">
                            <div class="boxName"><img src="<?php echo EVENT_STATIC_SERVER;?>/images/icons/icon_event_title.gif" alt="picture"/><span><?php echo $event->eid > 0?"<a href=\"/event/detail/".$event->eid."\">".$event->event_name."</a>":"Sự kiện mới";?></span></div>
                            <div class="tab float-right">
                                <div class="<?php echo $event->eid > 0?"tabItem2":"tabItem2S";?>"><span><a href="<?php echo $this->action == "info"?"#":"/event/edit/".$event->eid;?>">Thông tin sự kiện</a></span></div>
                                <?php if($event->eid > 0){?>
                                <div class="<?php echo $this->action == "picture"?"tabItem2S":"tabItem2";?>"><span><a href="<?php echo $this->action == "picture"?"#":"/event/edit/picture/".$event->eid;?>">Ảnh đại diện</a></span></div>
                                <div class="<?php echo $this->action == "member"?"tabItem2S":"tabItem2";?>"><span><a href="<?php echo $this->action == "member"?"#":"/event/edit/member/".$event->eid;?>">Thành viên</a></span></div>
                                <?php }?>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="boxBody">
                	<a href="/event/detail/<?php echo $event->eid;?>" class="back_SK">Quay về: <?php echo $event->event_name;?></a>
			        <a href="/event/member/<?php echo $event->eid;?>" style="margin: 7px 0px 8px 20px; display:inline-block;">Danh sách thành viên</a>
                    <div class="clear"></div>


<script language="JavaScript">
	
	key_handle=function(event)
	{
		var filterEl=$('#selector_name')[0];
		if(!filterEl)
		{
			return;
		}
		var filter=filterEl.value.toLowerCase().replace(/^\s*|\s*$/g, "");
		var user_list=$('#friends_list')[0];
		if (!user_list)
		{
			return;
		}
		var regex=new RegExp("^"+filter+"|\\s"+filter,"i");
		var len=user_list.childNodes.length;
		for(var i=0;i<len;i++)
		{
			var childEl=user_list.childNodes[i];
			if(!childEl)
			{
				continue;
			}
			if (childEl.tagName!="SPAN")
			{
				continue;
			}
			var name=childEl.getAttribute('u_name');
			if(regex.exec(name))
			{
				$(childEl).show();
			}
			else
			{
				$(childEl).hide();
			}
		}
	}
	
	
	
</script>
<style type="text/css">
.inputtext{
	border:1px solid #CCCCCC;
}
.inputtext:hover{
	border:1px solid #777777;
	background:transparent url(/images/bg-input-text.gif) repeat scroll left top;
}
.guestTypeSelect{
	border:1px solid #CCCCCC;
}
</style>
					<div class="sk_avatar_body editor_panel">
                    	<table cellspacing="0" cellpadding="6" border="0" width="98%">
                        	<style>
								.overflow-list-01,
								.overflow-list-02,
								.overflow-list-03 { overflow-y: scroll; height:423px; border:1px solid #ccc; padding:0.5em;}
								.overflow-list-01 { height:300px; margin-bottom:1em; }
							</style>
                        	<tr>
                        	  <td width="33%"><span class="title">Danh sách bạn bè:</span></td>
                        	  <td width="33%"><span class="title">Danh sách mời tham gia:</span></td>
                        	  <td><span class="title">Danh sách thành viên:</span></td>
                      	  	</tr>
                        	<tr style="background-color:#FFF;">
                        	  <td valign="top">
                        	  	Bạn có <span id="pending_count"><?php echo count($this->pending_list)?></span> người trong danh sách mời tham gia sự kiện
                        	  </td>
                        	  <td valign="top" style="border-left:5px solid #F5F9F0;">Hãy chọn người muốn mời từ danh sách bạn bè
                        	  	<input autocomplete="off" class="inputtext" id="selector_name" style="font-size: 12px; width: 98%; margin-top:5px; height:16px;" onkeyup="key_handle(event);">
                        	  	<?php if($this->isSiteAdmin){?>
                        	  	<span style="padding-top: 5px;">
                        	  		<input type="checkbox" id="check_all" />
                        	  		<label for="check_all">Chọn tất</label>
                        	  	</span>
                        	  	<?php }?>
                        	  </td>
                        	  <td valign="top" style="border-left:5px solid #F5F9F0;">
                        	  	<form action="/event/edit/member/<?php echo $event->eid;?>" method="POST">
                              	Hiển thị: 
                                <select name="view" id="view" onchange="submit();" class="guestTypeSelect">
									<option value="1" <?php echo ($this->view==1) ? 'selected="selected"' : ''?>>Thành viên</option>
									<option value="-1" <?php echo ($this->view==-1) ? 'selected="selected"' : ''?>>Chưa trả lời</option>
									<!-- <option value="0" <?php echo ($this->view==0) ? 'selected="selected"' : ''?>>Không tham gia</option> -->
									<option value="2" <?php echo ($this->view==2) ? 'selected="selected"' : ''?>>Có thể tham gia</option>
								</select>
                                
								<div class="clear"></div>
								<div style="margin-top:5px;">
									<em>
									<?
									if ($this->view==1)
										echo 'Thành viên tham gia sự kiện';
									else 
									//if ($this->view==0)
										//echo 'Thành viên không tham gia sự kiện';
									if ($this->view==2)
										echo 'Thành viên có thể tham gia sự kiện';
									else
										echo 'Thành viên chưa trả lời thư mời tham gia sự kiện';
									?>
									</em>
								</div>
								</form>
                              </td>
                            </tr>
                        	<tr style="background-color:#FFF;">
                            	<td valign="top">
                            		<form method="post" action="/event/edit/member/<?php echo $event->eid;?>" onsubmit="return event_member.checkPending();">
                                	<div class="overflow-list-01">
                                		<ul id="invitations">
											<?
											for ($i=0; $i<count($this->pending_list); $i++)
											{
												$u=$this->pending_list[$i];
											?>
												<li id="p_<?php echo $u->uid?>">
													<div class="name_row"><a href="/home/<?php echo $u->name;?>"><?php echo $u->name?></a></div>
													<div><a onclick="event_member.removePending(<?php echo $event->eid;?>, <?php echo $u->uid?>, '<?php echo $u->name?>'); return false;" u_name="<?php echo $u->name?>" id="<?php echo $u->uid?>" href="#">Loại bỏ</a></div>
												</li>
											<?
											}
											?>
										</ul>
                                	</div>
                                	<p><strong>Nội dung gửi kèm:</strong></p>
                                    <textarea style="width:97%; margin:0.5em 0;" rows="5" id="invite_msg" name="invite_msg"></textarea>
                                    <input type="hidden" name="invite" value="1">
                                    <input class="blogButton" value="Gửi thư mời" type="submit">
                                    
                                    </form>
                                    
                                </td>
                            	<td valign="top" style="border-left:5px solid #F5F9F0;">
                            		<div class="overflow-list-02">
                            			<div style="text-align: center; display: none;" id="friend_proccess">
											<img src="<?php echo EVENT_STATIC_SERVER;?>/images/loader.gif">
										</div>
										<div class="clear"></div>
                            			<span id="friends_list" style="font-size: 11px; line-height: 20px;">
											<?
											for ($i=0; $i<count($this->friend_list); $i++)
											{
												$u=$this->friend_list[$i];
												if(!in_array($u->uid, $this->friend_member_list) && !in_array($u->uid, $this->request_invited_list)){
											?>
											<span u_name="<?php echo $u->name?>" style="font-size: 11px; line-height: 20px;" id="friend_<?php echo $u->uid?>" u_id="<?php echo $u->uid?>">
												<input type="checkbox" value="<?php echo $u->uid?>" name="" id="i_friend_<?php echo $u->uid?>" " class="inputcheckbox canAdd" onclick="event_member.addPending(<?php echo $event->eid;?>, <?php echo $u->uid?>, '<?php echo $u->name?>')">
												<label id="lb_friend_<?php echo $u->uid?>" for="i_friend_<?php echo $u->uid?>" class="" style="font-size: 11px; line-height: 20px;"><?php echo $u->name?></label>
												<br style="font-size: 11px; line-height: 20px;">
											</span>
											<?
												}// End of if
											}// end of for
											?>
										</span>
                            		</div>
                            	</td>
                                <td valign="top" style="border-left:5px solid #F5F9F0;">
                                	<div class="overflow-list-03">
                                		<div id="member_proccess" style="text-align:center; display:none;">
											<img src="<?php echo EVENT_STATIC_SERVER;?>/images/loader.gif">
										</div>
                                		<ul id="invite_list">
											<?
											for ($i=0; $i<count($this->member_list); $i++)
											{
												$m=$this->member_list[$i];
												$u_name=$m->first_name . " " . $m->last_name;
												if ($m->uid==$this->user->uid)
												{
													$me=1;
												}
												else
												{
													$me=0;
												}
											?>
											<li class="clearfix" id="member_<?php echo $m->uid?>">
												<span class="name_row"><a href="/home/<?php echo $m->name;?>"><?php echo $m->name?></a></span>
												<span id="member_manage_link_<?php echo $m->uid?>">
												<?
												if ($this->view==1 && $this->isAdmin)
												{
													$admin=$m->admin;
												?>
													<a onclick="event_member.removeMember(<?php echo $event->eid;?>, <?php echo $m->uid?>, '<?php echo $u_name?>', <?php echo $me?>, <?php echo $admin?>); return false;" href="#">Loại bỏ</a> | 
												<?
													if ($admin==1){
														echo '<a onclick="event_member.removeAdmin('.$event->eid.', ' . $m->uid . ', \'' . $u_name . '\', \'' . "/event/removeadmin/" . $event->eid . "/" . $m->uid . '\', ' . $me . '); return false;" href="#">Hủy admin</a>';
													}
													else{
														echo '<a onclick="event_member.makeAdmin('.$event->eid.', ' . $m->uid . ', \'' . $u_name . '\'); return false;" href="#">Gán admin</a>';
													}
												}
												?>
												</span>
											</li>
											<?
											}
											?>
										</ul>
                                	</div>
                                </td>
                            </tr>
                        </table>
          <p>&nbsp;</p>
                        <p>&nbsp;</p>
                  	</div>
					<div class="clear"></div>
								        
			    </div>
                <div class="boxBottom"><span><b></b></span></div>
            </div>
            <!--End: event List-->
<script type="text/javascript">
	$(document).ready(function(){
		$("#check_all").click(function(){
			
			var status = this.checked;
			if(status){
				if(confirm('Bạn có chắc sẽ mời tất cả bạn bè của bạn vào sự kiện?')){
					$("input.canAdd").each(function(){
						this.checked = status;
						event_member.addPending(<?php echo $event->eid;?>, this.value, $('#lb_friend_'+this.value).html());
					});
				}
			}
			else{
				$("input.canAdd").each(function(){
					this.checked = status;
				});
			}
		});
	});
</script>